/*
 * GUIInit.cpp
 *
 *  Created on: 01.12.2011
 *      Author: Andrey Efimov
 *      Copyright: LGPL
 */

#ifndef _GUIINIT_H_
#define _GUIINIT_H_

#include "GUIBase.h"
#include <string>
#include <vector>
#include "../StructSource.h"
#include "../TThreadSafeQueue.h"

using namespace std;

class CNodeTree
{
public:
	CNodeTree* parent;	//��������� �� ��������
	CNodeTree* children;//��������� �� �������� ����
	CGuiBase* data;		//������
	CNodeTree* next;	//��������� �� ��������� ���� ������
	CNodeTree* prev;	//��������� �� ���������� ���� ������
	
	CNodeTree();
};

//--------����� �������� ��� ������---------------------------
class CTreeIterator
{
public:
	CNodeTree* first;	//������ ���� ������
	CNodeTree* current;	//������� ����

	CNodeTree* First();
	CNodeTree* Next();
	CNodeTree* NextXY(glm::vec2 MouseXY);
	bool CheckCollision(CGuiBase* data);
	bool AddNode(CGuiBase* data);	//�������� ����
	bool DelNode(CNodeTree* node, bool flag);	//������� ����

private:
	CTreeIterator();
	CTreeIterator(CNodeTree* f);
	friend class COwnerIterator;
};
//--------����� ��������� ���������---------------------------
class COwnerIterator
{
public:
	CTreeIterator TreeIterator;

	COwnerIterator();
	CTreeIterator* GetIterator();			//�������� ��������
	bool FreeIterator(CTreeIterator* TI);	//���������� ��������
};
//--------����� ��������--------------------------------------
class CShablon
{
public:
	vector<CLabel*>			ShablonLabel;
	vector<CEdit*>			ShablonEdit;
	vector<CMemo*>			ShablonMemo;
	vector<CListBox*>		ShablonListBox;
	vector<CComboBox*>		ShablonComboBox;
	vector<CButton*>		ShablonButton;
	vector<CCheckBox*>		ShablonCheckBox;
	vector<CRadioButton*>	ShablonRadioButton;
	vector<CProgressBar*>	ShablonProgressBar;
	vector<CTrackBar*>		ShablonTrackBar;
	vector<CPanel*>			ShablonPanel;
	vector<CInventar*>		ShablonInventar;

private:
	bool GetShablons( const char* FileShablon );
	friend class CManagerGUI;
};
//--------��������� ������ ���� ����������--------------------
struct SListNameControl
{
	std::string name;
	CNodeTree* node;
};
//--------������������----------------------------------------
enum EParam{PARAM_VISIBLE, PARAM_ENABLE, PARAM_NAME, PARAM_POSITION, PARAM_SIZE,
			PARAM_CURSOR, PARAM_TEXT, PARAM_ITEMS, PARAM_ITEMINDEX, PARAM_CHECKED,
			PARAM_GROUP, PARAM_MIN, PARAM_MAX, PARAM_VALUE, PARAM_SCROLLBARS};
//--------����� ��������� GUI---------------------------------
class CManagerGUI
{
private:
	static CManagerGUI* Manager;

	TThreadSafeQueue<UI_MESSAGE*> *messageQueue;

private:
	CManagerGUI();
	virtual ~CManagerGUI();

public:
	CShablon* Shablon;
	CNodeTree* CurrentFocus;
	CNodeTree* CurrentFocusMouse;
	COwnerIterator* OwnerIterator;
	SListNameControl ListNameControl[100];		//������ ���� ���������� (�� 100 ����)
	int LastPositionList;

	static CManagerGUI* GetInstance()
	{
		if ( NULL == Manager )
		{
			Manager = new CManagerGUI();
		}
		return Manager;
	}

	static void DestroyInstance()
	{
		if ( NULL != Manager )
		{
			delete Manager;
			Manager = NULL;
		}
	}

	bool Init(
		const char* FileShablon,
		const char* FileControl
		);
	CNodeTree* FindControl(std::string name);
	bool AddControl(std::string name, CGuiBase* data);
	bool DelControl(std::string name);
	bool MoveControl(std::string namefrom, std::string nameto);
	vector<GUI_ELEMENT*> Draw();
	bool EventMouse(USHORT KeyMouse, glm::vec2 MouseXY);
	bool EventBoardKey(USHORT Key);
	bool SetControlParam(std::string name, EParam param, void* value);
	bool GetControlParam(std::string name, EParam param);

	void SetMessageQueue( TThreadSafeQueue<UI_MESSAGE*> *MessageQueue );
};

#endif
